/*
 * Copyright (C) 2010 Seapeak.Xu
 *
 * fostmq may be copied only under the terms of the GNU General
 * Public License V3, which may be found in the fostmq source kit.
 *
 * Created on: 2010-8-20
 * Author: Seapeak.Xu
 */

#ifndef FOST_BUFF_H
#define FOST_BUFF_H
#ifdef __cplusplus
extern "C"
{
#endif

#include <sys/types.h>

/*
 * convert int32 value to stream buffer
 * parameters:
 * 	n:int value
 * 	buff:stream buffer
 * remarks:
 * 	the int value's sizeof is only 4
 * 	the stream buffer length is equal or more than 4,and end without '\0'
 */
void int2buff(const int n, char *buff);

/*
 * convert stream buffer to int32 value
 * parameters:
 * 	buff:the stream buffer
 * return:
 * 	int32 value
 * remarks:
 * 	int value's sizeof is only 4
 * 	stream length is equal or more than 4 
 */
int buff2int(const char *buff);

/*
 * convert int64(long long) value to stream buffer
 * parameters:
 * 	n:int64 value
 * 	buff:stream buffer
 * remarks:
 * 	int value's sizeof is only 8
 * 	stream buffer length is equal or more than 8,and end without '\0'
 */
void long2buff(int64_t n, char *buff);

/*
 * convert stream buffer to int64(long long) value
 * parameters:
 * 	buff:the stream buffer
 * return:
 * 	the int64(long long) value
 * remarks:
 * 	the int value's sizeof is only 8
 * 	the stream length is more than 8 
 */
int64_t buff2long(const char *buff);

#ifdef __cplusplus
}
#endif
#endif /* FOST_BUFF_H */
